#include "stdafx.h"
#include "RbsUserInfo.h"

#define TIMEOUT (120*1000)

CRbsUserInfo::CRbsUserInfo()
{
	ResetUserInfo();
}

CRbsUserInfo::~CRbsUserInfo(void)
{
}

INT64 CRbsUserInfo::GetUserID()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_oUser.m_i64UserId;
}

void CRbsUserInfo::ResetUserInfo()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_oUser.Initialize();
	m_nRoomID = 0;
	m_wClientVer = DEF_CLIENT_VER;
	m_nTcpConnetcTime = 0;
	m_nTcpLoginTime = 0;
	m_nTcpSessionKey = 0;
	m_nTcpIpAddr = 0;
	m_wTcpPort = 0;
	m_i64TcpALiveTime = CBaseThread::GetSystemTime();
	
	m_nUdpLoginTime = 0;
	m_nUdpSessionKey = 0;
	m_bIsLoginCms = FALSE;
	m_nUdpIpAddr = 0;
	m_wUdpPort = 0;
	m_i64UdpALiveTime = CBaseThread::GetSystemTime();

	m_bIsActive = FALSE;
	m_sMicIndex = INVALID_MICINDEX;
	m_eUserMicState = ENUM_USER_MIC_OK;
	m_dwPingValue = 0;
}

void CRbsUserInfo::SetUserInfo(STRU_CHAT_USER_INFO& aoUserInfo)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_oUser = aoUserInfo;
}
STRU_CHAT_USER_INFO& CRbsUserInfo::GetUserInfo(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_oUser;
}

void CRbsUserInfo::SetRoomID(int anRoomID)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nRoomID = anRoomID;
}
int CRbsUserInfo::GetRoomID(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_nRoomID;
}

WORD CRbsUserInfo::GetClientVer(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_wClientVer;
}

void CRbsUserInfo::IncTcpConnectTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpConnetcTime++;
}
void CRbsUserInfo::ResetTcpConnectTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpConnetcTime = 0;
}
BOOL CRbsUserInfo::IsTcpConnectTimeOut(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return (m_nTcpConnetcTime>5);
}

void CRbsUserInfo::IncTcpLoginTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpLoginTime++;
}

void CRbsUserInfo::ResetTcpLoginTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpLoginTime = 0;
}

BOOL CRbsUserInfo::IsTcpLoginTimeOut(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return (m_nTcpLoginTime>5);
}


void CRbsUserInfo::SetTcpSessionKey(int anTcpSessionKey)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpSessionKey = anTcpSessionKey;
}
int CRbsUserInfo::GetTcpSessionKey(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_nTcpSessionKey;
}

void CRbsUserInfo::SetTcpIpAndPort(int anTcpIpAddr, WORD awTcpPort)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nTcpIpAddr = anTcpIpAddr;
	m_wTcpPort = awTcpPort;
}
void CRbsUserInfo::GetTcpIpAndPort(int& anTcpIpAddr, WORD& awTcpPort)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	anTcpIpAddr = m_nTcpIpAddr;
	awTcpPort = m_wTcpPort;
}

void CRbsUserInfo::UpdateTcpALive(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_i64TcpALiveTime = CBaseThread::GetSystemTime();
}

BOOL CRbsUserInfo::IsTcpALiveTimeOut(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return (_abs64(CBaseThread::GetSystemTime()-m_i64TcpALiveTime) > TIMEOUT);
}

INT64 CRbsUserInfo::GetTcpALive(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_i64TcpALiveTime;
}

void CRbsUserInfo::IncUdpLoginTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nUdpLoginTime++; 
}
void CRbsUserInfo::ResetUdpLoginTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nUdpLoginTime = 0;
}
int	CRbsUserInfo::GetUdpLoginTime(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_nUdpLoginTime;
}

void CRbsUserInfo::SetUdpSessionKey(int anUdpSessionKey)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nUdpSessionKey = anUdpSessionKey;
}
int CRbsUserInfo::GetUdpSessionKey(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_nUdpSessionKey;
}

void CRbsUserInfo::SetLoginCmsState(BOOL abIsLoginCms)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_bIsLoginCms = abIsLoginCms;
}

BOOL CRbsUserInfo::GetLoginCmsState(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_bIsLoginCms;
}

void CRbsUserInfo::SetUdpIpAndPort(int anUdpIpAddr, WORD awUdpPort)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_nUdpIpAddr = anUdpIpAddr;
	m_wUdpPort = awUdpPort;
}

void CRbsUserInfo::GetUdpIpAndPort(int& anUdpIpAddr, WORD& awUdpPort)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	anUdpIpAddr = m_nUdpIpAddr;
	awUdpPort = m_wUdpPort;
}

sockaddr_in CRbsUserInfo::GetUdpAddr()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = m_nUdpIpAddr;
	addr.sin_port = htons(m_wUdpPort);
	return addr;
}

void CRbsUserInfo::UpdateUdpALive()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_i64UdpALiveTime = CBaseThread::GetSystemTime();
}

BOOL CRbsUserInfo::IsUdpALiveTimeOut()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return (_abs64(CBaseThread::GetSystemTime()-m_i64UdpALiveTime) > TIMEOUT);
}

INT64 CRbsUserInfo::GetUdpALive(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_i64UdpALiveTime;
}

void CRbsUserInfo::SetActiveState(BOOL abActiveState)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_bIsActive = abActiveState;
}
BOOL CRbsUserInfo::GetActiveState(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_bIsActive;
}

void CRbsUserInfo::SetMicIndex(short asMicIndex)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_sMicIndex = asMicIndex;
}
short CRbsUserInfo::GetMicIndex(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_sMicIndex;
}

void CRbsUserInfo::SetUserMicState(ENUM_USER_MIC_STATE anMicState)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_eUserMicState = anMicState;
}

ENUM_USER_MIC_STATE CRbsUserInfo::GetUserMicState()
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_eUserMicState;
}

void CRbsUserInfo::SetUdpPingValue(DWORD adwPingValue)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	m_dwPingValue = adwPingValue;
}

DWORD CRbsUserInfo::GetUdpPingValue(void)
{
	CCriticalAutoLock loAutoLock(m_oCSUser);
	return m_dwPingValue;
}
